package com.lanchetech.merchant.controller;

import com.lanchetech.bean.request.FreezeAmountReq;
import com.lanchetech.bean.request.PageReq;
import com.lanchetech.bean.response.BasePageResp;
import com.lanchetech.bean.response.BaseResp;
import com.lanchetech.bean.response.ResultData;
import com.lanchetech.bean.vo.FreezeAmountVO;
import com.lanchetech.bean.vo.TenantFundVO;
import com.lanchetech.entity.BalanceFlow;
import com.lanchetech.entity.TenantFlow;
import com.lanchetech.entity.TenantWithdraw;
import com.lanchetech.merchant.aop.OperatorLog;
import com.lanchetech.merchant.service.FundService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.math.BigDecimal;

@Api(value = "资金管理接口", tags = "资金管理接口")
@RequestMapping("/api/fund")
@RestController
public class FundController {

    @Autowired
    FundService fundService;

    @ApiOperation("获取商家提现分页")
    @PreAuthorize("hasAuthority('fund.index')")
    @PostMapping("/getTenantWithdrawPage")
    public ResultData<BasePageResp<TenantWithdraw>> getTenantWithdrawPage(@RequestBody PageReq req) {
        return fundService.getTenantWithdrawPage(req);
    }

    @OperatorLog(value = "发起商家提现申请")
    @ApiOperation("发起商家提现申请")
    @PreAuthorize("hasAuthority('fund.index.withdraw.auth')")
    @PostMapping("/createTenantWithdraw")
    public BaseResp createTenantWithdraw(@RequestBody TenantWithdraw req) {
        return fundService.createTenantWithdraw(req);
    }

    @ApiOperation("获取商家资金信息")
    @PreAuthorize("hasAuthority('fund.index.withdraw.auth')")
    @GetMapping("/getTenantFundInfo")
    public ResultData<TenantFundVO> getTenantFundInfo() {
        return fundService.getTenantFundInfo();
    }

    @ApiOperation("积分充值")
    @PreAuthorize("hasAuthority('fund.detail.coin.auth')")
    @GetMapping("/topUpCoin")
    public BaseResp topUpCoin(@RequestParam("coin")BigDecimal coin) {
        return fundService.topUpCoin(coin);
    }

    @ApiOperation("获取商家余额流水")
    @PreAuthorize("hasAuthority('fund.detail')")
    @PostMapping("/getBalanceFlowPage")
    public ResultData<BasePageResp<TenantFlow>>  getBalanceFlowPage(@RequestBody PageReq req) {
        return fundService.getBalanceFlowPage(req);
    }

    @ApiOperation("获取商家冻结金额分页")
    @PostMapping("/getFreezeAmountPage")
    public ResultData<BasePageResp<FreezeAmountVO>>  getFreezeAmountPage(@RequestBody FreezeAmountReq req) {
        return fundService.getFreezeAmountPage(req);
    }
}
